import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UploadedFile,
  BadRequestException,
  Req,
  HttpCode,
} from '@nestjs/common';
import { ChangeUserAvatarService } from './change-user-avatar.service';
import { CreateChangeUserAvatarDto } from './dto/create-change-user-avatar.dto';
import { UpdateChangeUserAvatarDto } from './dto/update-change-user-avatar.dto';
import { Auth } from 'src/jwt/jwt.decorator';
import { ImageUpload } from './change-avater.decorator';
import {
  ApiBearerAuth,
  ApiBody,
  ApiOperation,
  ApiResponse,
} from '@nestjs/swagger';
import { responseChangeUserAvatar } from './entities/Response';
import { ChangeUserAvatar } from './entities/change-user-avatar.entity';

@Controller('changeUserAvatar')
export class ChangeUserAvatarController {
  constructor(private readonly service: ChangeUserAvatarService) {}

  @Post()
  @Auth()
  @ImageUpload()
  @HttpCode(200)
  @ApiOperation({ summary: '修改头像接口' })
  @ApiBody({ type: ChangeUserAvatar, description: '请输入你要上传的文件' })
  @ApiBearerAuth()
  @ApiResponse({
    status: 200,
    description: '修改头像成功',
    type: responseChangeUserAvatar,
  })
  create(@Req() req: any, @UploadedFile() file: any) {
    if (!file) {
      throw new BadRequestException('要修改的头像不能为空,必须添加');
    }
    return this.service.create(req, file);
  }
}
